<template>
  <el-form :model="formInline" label-width="100">
    <el-form-item label="听课时间">
      <DatePicker v-model="formInline.date"></DatePicker>
    </el-form-item>
    <el-form-item label="课时">
      <el-input v-model="formInline.unitClassHours" placeholder="请输入课时" clearable />
    </el-form-item>
    <el-form-item label="授课教师">
      <el-input v-model="formInline.teacher" placeholder="请输入授课教师" clearable />
    </el-form-item>
    <el-form-item label="培训职业">
      <el-input v-model="formInline.trainingProfession" placeholder="请输入培训职业" clearable />
    </el-form-item>
    <el-form-item label="级别">
      <el-input v-model="formInline.level" placeholder="请输入级别" clearable />
    </el-form-item>
    <el-form-item label="班级">
      <el-input v-model="formInline.className" placeholder="请输入班级" clearable />
    </el-form-item>
    <el-form-item label="授课内容">
      <el-input v-model="formInline.teachingContent" type="textarea" placeholder="请输入授课内容" :autosize="{ minRows: 4 }" clearable />
    </el-form-item>
    <el-form-item label="听课记录">
      <el-input v-model="formInline.listeningRecord" type="textarea" placeholder="请输入听课记录" :autosize="{ minRows: 4 }" clearable />
    </el-form-item>
    <el-form-item label="随堂印象">
      <el-input v-model="formInline.impression" type="textarea" placeholder="请输入随堂印象" :autosize="{ minRows: 4 }" clearable />
    </el-form-item>
    <el-form-item label="总体评价">
      <el-input v-model="formInline.overallEvaluation" type="textarea" placeholder="请输入总体评价" :autosize="{ minRows: 4 }" clearable />
    </el-form-item>
  </el-form>

  <div class="actionBtn flex">
    <el-button type="primary" @click="save" :loading="loading">保 存</el-button>
  </div>
</template>

<script setup lang="ts">
const { proxy } = getCurrentInstance();
import useCounterStore from "@/store/counter";
const counter = useCounterStore();
let props = defineProps(["info"]);

let formInline = ref({
  trainingProfession: "",
  level: "",
  className: "",
  unitClassHours: "",
  date: "",
  teachingContent: "",
  listeningRecord: "", //听课记录
  impression: "", //随堂印象
  overallEvaluation: "", //总体评价
  teacher: "",
});
let initData = ref([]); //原始数据
let loading = ref(false);

async function getInfo() {
  let resp = await proxy.$apis.classLessonEvaluation({
    type: "details",
    data: { classId: props.info._id },
  });
  if (resp) {
    formInline.value = proxy.$utils.formatFunction(resp, {
      ...formInline.value,
    });
  }
}

async function save() {
  try {
    loading.value = true;
    let query = { ...formInline.value };
    query["classId"] = props.info._id;
    await proxy.$apis.classLessonEvaluation({
      type: "update",
      data: query,
    });
    proxy.$utils.showToast("保存成功");
    getInfo();
  } catch (error) {
  } finally {
    loading.value = false;
  }
}

watch(
  () => props.info,
  (newValue, oldValue) => {
    if (newValue) {
      getInfo();
    }
  },
  { deep: true, immediate: true }
);
</script>



<style lang="scss" scoped>
.actionBtn {
  justify-content: flex-end;
  margin-top: 15px;
}
</style>

